package com.qf.commerce.controller;

import com.github.pagehelper.PageInfo;
import com.qf.commerce.common.dto.GoodsReturnedDto;
import com.qf.commerce.common.dto.ReturnMoneyDto;
import com.qf.commerce.common.vo.GoodsReturnedVo;
import com.qf.commerce.exception.ControllerException;
import com.qf.commerce.resp.ResponseResult;
import com.qf.commerce.resp.ResponseStatus;
import com.qf.commerce.service.GoodsReturnedService;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/return")
public class GoodsReturnedController {
    @Resource
    GoodsReturnedService goodsReturnedService;
    @GetMapping("/list")
    public ResponseResult<PageInfo<GoodsReturnedVo>> queryGoodReturned(@RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "20")int size, GoodsReturnedDto goodsReturnedDto){
        return ResponseResult.success(goodsReturnedService.queryGoodsReturned(page,size,goodsReturnedDto));
    }
    @DeleteMapping("/del")
    public ResponseResult<Integer> delGoodReturnedById(@RequestBody List<Long> returnOrderId){
        if (ObjectUtils.isEmpty(returnOrderId)){
            throw new ControllerException(ResponseStatus.DATA_ERROR);
        }
        return ResponseResult.success(goodsReturnedService.delGoodReturnedById(returnOrderId));
    }
    @PutMapping("/deliver")
    public ResponseResult<Integer> upDeliveryById(@RequestBody List<Long> returnOrderId){
        if (ObjectUtils.isEmpty(returnOrderId)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(goodsReturnedService.upDeliveryById(returnOrderId));
    }
    @PutMapping("/more/money")
    public ResponseResult<Integer> upReturnMoneyById(@RequestBody ReturnMoneyDto returnMoneyDto){
        if (ObjectUtils.isEmpty(returnMoneyDto)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(goodsReturnedService.upReturnMoneyById(returnMoneyDto.getReturnOrderId(),returnMoneyDto.getReturnMoney()));
    }
    @GetMapping("/zone")
    public ResponseResult<List<GoodsReturnedVo>> queryReturnZone(){
        return ResponseResult.success(goodsReturnedService.queryGoodsZone());
    }
    @GetMapping("/lower")
    public ResponseResult<List<GoodsReturnedVo>> queryReturnLower(){
        return ResponseResult.success(goodsReturnedService.queryGoodsLower());
    }
    @GetMapping("/one")
    public ResponseResult<List<GoodsReturnedVo>> queryReturnOne(){
        return ResponseResult.success(goodsReturnedService.queryGoodsOne());
    }
    @GetMapping("/two")
    public ResponseResult<List<GoodsReturnedVo>> queryReturnTwo(){
        return ResponseResult.success(goodsReturnedService.queryGoodsTwo());
    }
    @GetMapping("/three")
    public ResponseResult<List<GoodsReturnedVo>> queryReturnThree(){
        return ResponseResult.success(goodsReturnedService.queryGoodsThree());
    }
    @GetMapping("/four")
    public ResponseResult<List<GoodsReturnedVo>> queryReturnFour(){
        return ResponseResult.success(goodsReturnedService.queryGoodsFour());
    }

    @GetMapping("/five")
    public ResponseResult<List<GoodsReturnedVo>> queryReturnFive(){
        return ResponseResult.success(goodsReturnedService.queryGoodsFive());
    }

    @GetMapping("/goodsDetail")
    public ResponseResult<GoodsReturnedVo> queryReturnDetail(@RequestParam Long returnOrderId){
        if(ObjectUtils.isEmpty(returnOrderId)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(goodsReturnedService.queryGoodsDetail(returnOrderId));
    }

    @PutMapping("/inject")
    public ResponseResult<Integer> upReturnInject(@RequestBody GoodsReturnedDto goodsReturnedDto){
        if(ObjectUtils.isEmpty(goodsReturnedDto)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(goodsReturnedService.upGoodsReturnInject(goodsReturnedDto));
    }

    @PutMapping("/can")
    public ResponseResult<Integer> upReturnCan(@RequestBody GoodsReturnedDto goodsReturnedDto){
        if(ObjectUtils.isEmpty(goodsReturnedDto)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(goodsReturnedService.upGoodsReturnCan(goodsReturnedDto));
    }

    @PutMapping("/receive")
    public ResponseResult<Integer> upReturnReceive(@RequestBody GoodsReturnedDto goodsReturnedDto){
        if(ObjectUtils.isEmpty(goodsReturnedDto)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(goodsReturnedService.upReturnReceive(goodsReturnedDto));
    }

    @PutMapping("/abnormal")
    public ResponseResult<Integer> upReturnAbnormalReceive(@RequestBody GoodsReturnedDto goodsReturnedDto){
        if(ObjectUtils.isEmpty(goodsReturnedDto)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(goodsReturnedService.upReturnAbnormalReceive(goodsReturnedDto));
    }

    @PutMapping("/money/only")
    public ResponseResult<Integer> upReturnMoney(@RequestBody GoodsReturnedDto goodsReturnedDto){
        if(ObjectUtils.isEmpty(goodsReturnedDto)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(goodsReturnedService.upReturnMoney(goodsReturnedDto));
    }

    @PutMapping("/abnormal/reason")
    public ResponseResult<Integer> upReturnAbnormalReason(@RequestBody GoodsReturnedDto goodsReturnedDto){
        if(ObjectUtils.isEmpty(goodsReturnedDto)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(goodsReturnedService.upAbnormalReturnReason(goodsReturnedDto));
    }

    @GetMapping("/return/waybill")
    public ResponseResult<GoodsReturnedVo> queryReturnWayBill(@RequestParam GoodsReturnedDto goodsReturnedDto){
        if(ObjectUtils.isEmpty(goodsReturnedDto)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(goodsReturnedService.queryReturnWaybill(goodsReturnedDto));
    }
}
